/**
* @Title: insuredBlacklist_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @author EX-XIEYUWEN001
* @date 2014年10月29日 下午14:46:06
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('selectDispatchUserModalCtrl', ['$scope', '$http','BaseURL', 'Modal','$modalInstance','CaseAuditDispathService','CaseCommonService', 
	                                               function($scope, $http, baseUrl, Modal,$modalInstance,CaseAuditDispathService,CaseCommonService){
		$scope.userInfoList=[];
		function initRoleUserInfo(){
			var parameter={};
			CaseCommonService.loadUserInfoByRoleName(parameter).success(function(response){
		    	     var list=response.data;
		    	     $.each(list,function(index,item){
		    	    	 var displayName=item.displayName;
		    	    	 var username=item.username;
		    	    	 var obj={
		    	    			 code:username,
		    	    			 name:username+"  "+displayName
		    	    	 };
		    	    	 $scope.userInfoList.push(obj);
		    	     });
				});
		}
		//初始化数据
		initRoleUserInfo();
	
		$scope.selectUserInfoList= [];
		//关闭model
		$scope.onClose = function() {
			$modalInstance.close();
		}
		
		/***
		 * 生成随机数
		 */
		function getRandomNum(){
			var listSize=$scope.userInfoList.length;
			
		    var randNum=Math.floor(Math.random()*listSize);
		 
		   return $scope.userInfoList[randNum].code;
			
		}
		
		/**
		 * 分配确定事件
		 */
		$scope.dispatchConfirm = function() {
			var selected = $("#userInfomations").val();
			if (!selected) {
					Modal.alert("请选择经办人员");
					return;
			}else if(selected.length>1){
					Modal.alert("只能选择一位经办人员");
					return;
			}
			var parameter={
					userCode:selected[0],
					problemNo:$scope.problemNo,
					warnMarkTempDetails:$scope.warnMarkTempDetails
			}
			CaseAuditDispathService.dispatchUser(parameter).success(function(response){
		           var currentFlag=response.flag;
		           if(currentFlag){
		        	   $modalInstance.close();
		        	   $scope.dispatchBackClick();
		        	   //给出提示框
		        	   Modal.alert(response.msg);
		        	  // $scope.saveStaffAndInsuarnceInfo();
		           }
			});
		 }
		
		/**
		 * 随机选择
		 */
		$scope.randDispatchConfirm=function(){
			var userCode=getRandomNum();
			$("#userInfomations").val(userCode);
		}	
		
	}]);
})();
